/**
 * Copyright (c) 2010-2020 by skzr.org
 * All rights reserved.
 * @Author <a href="mailto:skzr.org@gmail.com">skzr.org</a>
 * @date 2011-3-14 下午09:20:32
 */
package org.skzr.logging.impl; // NOPMD by skzrorg on 11-3-15 下午12:43

import java.text.MessageFormat;

import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
import org.slf4j.helpers.FormattingTuple;
import org.slf4j.helpers.MessageFormatter;
import org.slf4j.spi.LocationAwareLogger;

/**
 * @author <a href="mailto:skzr.org@gmail.com">skzr.org</a>
 * @version 1.0.0
 * @since JDK1.6
 */
public class SLF4JLocationAwareLog extends AbstractLocalLogger<LocationAwareLogger> { // NOPMD by skzrorg on 11-3-15 下午12:43
	protected static final Marker LOCALIZED = MarkerFactory.getMarker("LOCALIZED");
	private static final String FQCN = SLF4JLocationAwareLog.class.getName();

	public SLF4JLocationAwareLog(LocationAwareLogger logger, MessageConveyor messageConveyor) {
		super(logger, messageConveyor);
	}
	
	@Override
	public void debug(Marker marker, String msg) {
		if (logger.isDebugEnabled()) logger.log(marker, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, null);
	}

	@Override
	public void debug(Marker marker, String format, Object arg) {
		if (logger.isDebugEnabled()) {
			FormattingTuple tuple = MessageFormatter.format(format, arg);
			logger.log(marker, FQCN, LocationAwareLogger.DEBUG_INT, tuple.getMessage(), tuple.getArgArray(), tuple.getThrowable());
		}
	}

	@Override
	public void debug(Marker marker, String format, Object arg1, Object arg2) {
		if (logger.isDebugEnabled()) {
			logger.log(marker, FQCN, LocationAwareLogger.DEBUG_INT, 
				MessageFormatter.format(format, arg1, arg2).getMessage(), new Object[]{arg1, arg2}, null);
		}
	}

	@Override
	public void debug(Marker marker, String format, Object[] argArray) {
		if (logger.isDebugEnabled()) {
			FormattingTuple tuple = MessageFormatter.arrayFormat(format, argArray);
			logger.log(marker, FQCN, LocationAwareLogger.DEBUG_INT, tuple.getMessage(), argArray, tuple.getThrowable());
		}
	}

	@Override
	public void debug(Marker marker, String msg, Throwable throwable) {
		if (logger.isDebugEnabled()) logger.log(marker, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, throwable);
	}

	@Override
	public void debug(String msg) {
		if (logger.isDebugEnabled()) logger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, null);
	}

	@Override
	public void debug(String format, Object arg) {
		if (logger.isDebugEnabled()) {
			logger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, 
					MessageFormatter.format(format, arg).getMessage(), new Object[] { arg }, null);
		}
	}

	@Override
	public void debug(String format, Object arg1, Object arg2) {
		if (logger.isDebugEnabled()) {
			logger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, MessageFormatter.format(format, arg1, arg2).getMessage(),
					new Object[] { arg1, arg2 }, null);
		}
	}

	@Override
	public void debug(String format, Object[] argArray) {
		if (logger.isDebugEnabled()) {
			FormattingTuple tuple = MessageFormatter.arrayFormat(format, argArray);
			logger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, tuple.getMessage(),
					tuple.getArgArray(), tuple.getThrowable());
		}
	}

	@Override
	public void debug(String msg, Throwable throwable) {
		if (logger.isDebugEnabled()) logger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, throwable);
	}

	@Override
	public void error(Marker marker, String msg) {
		if (logger.isErrorEnabled()) {
			logger.log(marker, FQCN, LocationAwareLogger.ERROR_INT, msg, null, null);
		}
	}

	@Override
	public void error(Marker marker, String format, Object arg) {
		if (logger.isErrorEnabled()) {
			String formattedMessage = MessageFormatter.format(format, arg).getMessage();
			logger.log(marker, FQCN, LocationAwareLogger.ERROR_INT, formattedMessage,
					new Object[] { arg }, null);
		}
	}

	@Override
	public void error(Marker marker, String format, Object arg1, Object arg2) {
		if (logger.isErrorEnabled()) {
			String formattedMessage = MessageFormatter.format(format, arg1, arg2).getMessage();
			logger.log(marker, FQCN, LocationAwareLogger.ERROR_INT, formattedMessage,
					new Object[] { arg1, arg2 }, null);
		}
	}

	@Override
	public void error(Marker marker, String format, Object[] argArray) {
		if (logger.isErrorEnabled()) {
			String formattedMessage = MessageFormatter.arrayFormat(format, argArray).getMessage();
			logger.log(marker, FQCN, LocationAwareLogger.ERROR_INT, formattedMessage, argArray,
					null);
		}
	}

	@Override
	public void error(Marker marker, String msg, Throwable throwable) {
		if (logger.isErrorEnabled()) {
			logger.log(marker, FQCN, LocationAwareLogger.ERROR_INT, msg, null, throwable);
		}
	}

	@Override
	public void error(String msg) {
		if (logger.isErrorEnabled()) {
			logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, msg, null, null);
		}
	}

	@Override
	public void error(String format, Object arg) {
		if (logger.isErrorEnabled()) {
			String formattedMessage = MessageFormatter.format(format, arg).getMessage();
			logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, formattedMessage,
					new Object[] { arg }, null);
		}
	}

	@Override
	public void error(String format, Object arg1, Object arg2) {
		if (logger.isErrorEnabled()) {
			String formattedMessage = MessageFormatter.format(format, arg1, arg2).getMessage();
			logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, formattedMessage,
					new Object[] { arg1, arg2 }, null);
		}
	}

	@Override
	public void error(String format, Object[] argArray) {
		if (logger.isErrorEnabled()) {
			String formattedMessage = MessageFormatter.arrayFormat(format, argArray).getMessage();
			logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, formattedMessage, argArray,
					null);
		}
	}

	@Override
	public void error(String msg, Throwable throwable) {
		if (logger.isErrorEnabled()) {
			logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, msg, null, throwable);
		}
	}

	@Override
	public void info(Marker marker, String msg) {
		if (logger.isInfoEnabled()) {
			logger.log(marker, FQCN, LocationAwareLogger.INFO_INT, msg, null, null);
		}
	}

	@Override
	public void info(Marker marker, String format, Object arg) {
		if (logger.isInfoEnabled()) {
			String formattedMessage = MessageFormatter.format(format, arg).getMessage();
			logger.log(marker, FQCN, LocationAwareLogger.INFO_INT, formattedMessage,
					new Object[] { arg }, null);
		}
	}

	@Override
	public void info(Marker marker, String format, Object arg1, Object arg2) {
		if (logger.isInfoEnabled()) {
			String formattedMessage = MessageFormatter.format(format, arg1, arg2).getMessage();
			logger.log(marker, FQCN, LocationAwareLogger.INFO_INT, formattedMessage,
					new Object[] { arg1, arg2 }, null);
		}
	}

	@Override
	public void info(Marker marker, String format, Object[] argArray) {
		if (logger.isInfoEnabled()) {
			String formattedMessage = MessageFormatter.arrayFormat(format, argArray).getMessage();
			logger.log(marker, FQCN, LocationAwareLogger.INFO_INT, formattedMessage, argArray,
					null);
		}
	}

	@Override
	public void info(Marker marker, String msg, Throwable throwable) {
		if (logger.isInfoEnabled()) {
			logger.log(marker, FQCN, LocationAwareLogger.INFO_INT, msg, null, throwable);
		}
	}

	@Override
	public void info(String msg) {
		if (logger.isInfoEnabled()) {
			logger.log(null, FQCN, LocationAwareLogger.INFO_INT, msg, null, null);
		}
	}

	@Override
	public void info(String format, Object arg) {
		if (logger.isInfoEnabled()) {
			String formattedMessage = MessageFormatter.format(format, arg).getMessage();
			logger.log(null, FQCN, LocationAwareLogger.INFO_INT, formattedMessage,
					new Object[] { arg }, null);
		}
	}

	@Override
	public void info(String format, Object arg1, Object arg2) {
		if (logger.isInfoEnabled()) {
			String formattedMessage = MessageFormatter.format(format, arg1, arg2).getMessage();
			logger.log(null, FQCN, LocationAwareLogger.INFO_INT, formattedMessage,
					new Object[] { arg1, arg2 }, null);
		}
	}

	@Override
	public void info(String format, Object[] argArray) {
		if (logger.isInfoEnabled()) {
			String formattedMessage = MessageFormatter.arrayFormat(format, argArray).getMessage();
			logger.log(null, FQCN, LocationAwareLogger.INFO_INT, formattedMessage, argArray,
					null);
		}
	}

	@Override
	public void info(String msg, Throwable throwable) {
		if (logger.isInfoEnabled()) {
			logger.log(null, FQCN, LocationAwareLogger.INFO_INT, msg, null, throwable);
		}
	}

	@Override
	public void trace(Marker marker, String msg) {
		if (logger.isTraceEnabled()) {
			logger.log(marker, FQCN, LocationAwareLogger.TRACE_INT, msg, null, null);
		}
	}

	@Override
	public void trace(Marker marker, String format, Object arg) {
		if (logger.isTraceEnabled()) {
			String formattedMessage = MessageFormatter.format(format, arg).getMessage();
			logger.log(marker, FQCN, LocationAwareLogger.TRACE_INT, formattedMessage,
					new Object[] { arg }, null);
		}
	}

	@Override
	public void trace(Marker marker, String format, Object arg1, Object arg2) {
		if (logger.isTraceEnabled()) {
			String formattedMessage = MessageFormatter.format(format, arg1, arg2).getMessage();
			logger.log(marker, FQCN, LocationAwareLogger.TRACE_INT, formattedMessage,
					new Object[] { arg1, arg2 }, null);
		}
	}

	@Override
	public void trace(Marker marker, String format, Object[] argArray) {
		if (logger.isTraceEnabled()) {
			String formattedMessage = MessageFormatter.arrayFormat(format, argArray).getMessage();
			logger.log(marker, FQCN, LocationAwareLogger.TRACE_INT, formattedMessage, argArray,
					null);
		}
	}

	@Override
	public void trace(Marker marker, String msg, Throwable throwable) {
		if (logger.isTraceEnabled()) {
			logger.log(marker, FQCN, LocationAwareLogger.TRACE_INT, msg, null, throwable);
		}
	}

	@Override
	public void trace(String msg) {
		if (logger.isTraceEnabled()) {
			logger.log(null, FQCN, LocationAwareLogger.TRACE_INT, msg, null, null);
		}
	}

	@Override
	public void trace(String format, Object arg) {
		if (logger.isTraceEnabled()) {
			String formattedMessage = MessageFormatter.format(format, arg).getMessage();
			logger.log(null, FQCN, LocationAwareLogger.TRACE_INT, formattedMessage,
					new Object[] { arg }, null);
		}
	}

	@Override
	public void trace(String format, Object arg1, Object arg2) {
		if (logger.isTraceEnabled()) {
			String formattedMessage = MessageFormatter.format(format, arg1, arg2).getMessage();
			logger.log(null, FQCN, LocationAwareLogger.TRACE_INT, formattedMessage,
					new Object[] { arg1, arg2 }, null);
		}
	}

	@Override
	public void trace(String format, Object[] argArray) {
		if (logger.isTraceEnabled()) {
			String formattedMessage = MessageFormatter.arrayFormat(format, argArray).getMessage();
			logger.log(null, FQCN, LocationAwareLogger.TRACE_INT, formattedMessage, argArray,
					null);
		}
	}

	@Override
	public void trace(String msg, Throwable throwable) {
		if (logger.isTraceEnabled()) {
			logger.log(null, FQCN, LocationAwareLogger.TRACE_INT, msg, null, throwable);
		}
	}

	@Override
	public void warn(Marker marker, String msg) {
		if (logger.isWarnEnabled()) {
			logger.log(marker, FQCN, LocationAwareLogger.WARN_INT, msg, null, null);
		}
	}

	@Override
	public void warn(Marker marker, String format, Object arg) {
		if (logger.isWarnEnabled()) {
			String formattedMessage = MessageFormatter.format(format, arg).getMessage();
			logger.log(marker, FQCN, LocationAwareLogger.WARN_INT, formattedMessage,
					new Object[] { arg }, null);
		}
	}

	@Override
	public void warn(Marker marker, String format, Object arg1, Object arg2) {
		if (logger.isWarnEnabled()) {
			String formattedMessage = MessageFormatter.format(format, arg1, arg2).getMessage();
			logger.log(marker, FQCN, LocationAwareLogger.WARN_INT, formattedMessage,
					new Object[] { arg1, arg2 }, null);
		}
	}

	@Override
	public void warn(Marker marker, String format, Object[] argArray) {
		if (logger.isWarnEnabled()) {
			String formattedMessage = MessageFormatter.arrayFormat(format, argArray).getMessage();
			logger.log(marker, FQCN, LocationAwareLogger.WARN_INT, formattedMessage, argArray,
					null);
		}
	}

	@Override
	public void warn(Marker marker, String msg, Throwable throwable) {
		if (logger.isWarnEnabled()) {
			logger.log(marker, FQCN, LocationAwareLogger.WARN_INT, msg, null, throwable);
		}
	}

	@Override
	public void warn(String msg) {
		if (logger.isWarnEnabled()) {
			logger.log(null, FQCN, LocationAwareLogger.WARN_INT, msg, null, null);
		}
	}

	@Override
	public void warn(String format, Object arg) {
		if (logger.isWarnEnabled()) {
			String formattedMessage = MessageFormatter.format(format, arg).getMessage();
			logger.log(null, FQCN, LocationAwareLogger.WARN_INT, formattedMessage,
					new Object[] { arg }, null);
		}
	}

	@Override
	public void warn(String format, Object arg1, Object arg2) {
		if (logger.isWarnEnabled()) {
			String formattedMessage = MessageFormatter.format(format, arg1, arg2).getMessage();
			logger.log(null, FQCN, LocationAwareLogger.WARN_INT, formattedMessage,
					new Object[] { arg1, arg2 }, null);
		}
	}

	@Override
	public void warn(String format, Object[] argArray) {
		if (logger.isWarnEnabled()) {
			logger.log(null, FQCN, LocationAwareLogger.WARN_INT,
					MessageFormatter.arrayFormat(format, argArray).getMessage(), argArray, null);
		}
	}

	@Override
	public void warn(String msg, Throwable throwable) {
		if (logger.isWarnEnabled()) logger.log(null, FQCN, LocationAwareLogger.WARN_INT, msg, null, throwable);
	}

	@Override
	public void trace(Enum<?> key, Object... args) {
		if (logger.isTraceEnabled()) {
			logger.log(LOCALIZED, FQCN, LocationAwareLogger.TRACE_INT,
					MessageFormat.format(getMessage(key, args), args), args, getThrowableCandidate(args));
		}
	}

	@Override
	public void debug(Enum<?> key, Object... args) {
		if (logger.isDebugEnabled()) {
			logger.log(LOCALIZED, FQCN, LocationAwareLogger.DEBUG_INT,
					MessageFormat.format(getMessage(key, args), args), args, getThrowableCandidate(args));
		}
	}

	@Override
	public void info(Enum<?> key, Object... args) {
		if (logger.isInfoEnabled()) {
			logger.log(LOCALIZED, FQCN, LocationAwareLogger.INFO_INT,
					MessageFormat.format(getMessage(key, args), args), args, getThrowableCandidate(args));
		}
	}

	@Override
	public void warn(Enum<?> key, Object... args) {
		if (logger.isWarnEnabled()) {
			logger.log(LOCALIZED, FQCN, LocationAwareLogger.WARN_INT,
					MessageFormat.format(getMessage(key, args), args), args, getThrowableCandidate(args));
		}
	}

	@Override
	public void error(Enum<?> key, Object... args) {
		if (logger.isErrorEnabled()) {
			logger.log(LOCALIZED, FQCN, LocationAwareLogger.ERROR_INT,
					MessageFormat.format(getMessage(key, args), args), args, getThrowableCandidate(args));
		}
	}

}
